package database

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"im/model"
	"log"
)

var DbCone *xorm.Engine

func init() {
	var err error
	drivename := "mysql"
	dsname := "root:ywh123456@(127.0.0.1:3306)/chat?charset=utf8"
	DbCone,err = xorm.NewEngine(drivename,dsname)
	if nil != err {
		log.Fatal(err.Error())
	}
	//debug 显示sql语句比较好调试
	DbCone.ShowSQL(true)
	//最大连接数
	DbCone.SetMaxOpenConns(2)
	//初始化表
	DbCone.Sync2(new(model.User),new(model.Contact),new(model.Community))

	println("init Db success")
}
